﻿angular.module('AceApp')
//.controller('Demo01Ctrl', function ($scope, $http, $timeout, $rootScope) {
//angular.module('AceApp').controller('WizardCtrl', function($scope, $timeout, WizardHandler) {
.controller("DemoCtrl", function ($scope, $timeout, $http) {
    //$scope.alert = {
    //    'shown': true,
    //    'close': function () {
    //        $scope.alert.shown = false;
    //    }
    //}

    $scope.param = {
        url: ''
    };
    $scope.target = {
        shortUrl: '',
        longUrl: ''
    };

    //检查格式
    function CheckInput() {
        if ($scope.param.url == undefined || $scope.param.url == '') {
            console.log('请输入需要转换的路径地址！');
            //$scope.alert('请输入需要转换的路径地址！');
            return false;
        }
        return true;
    }

    //获取短路径
    $scope.GetShortUrlOld = function () {
        if (!CheckInput()) {
            return;
        }
        $.ajax({
            type: 'GET',
            url: '/api/Demo/GetShortUrl',
            data: { longUrl: $scope.param.url },
            dataType: 'json',
            success: function (data, textStatus) {
                if (data.success) {
                    $scope.target.shortUrl = data.data;
                    console.log(data.data);
                    $scope.apply();
                    //请求成功
                } else {
                    console.log(data.Message);
                    //请求失败
                }
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                console.log(xmlHttpRequest.responseText)
                //$scope.alert(xmlHttpRequest.responseText);
            }
        });
    }

    $scope.GetShortUrl = function () {
        if (!CheckInput()) {
            return;
        }
        $.ajax({
            type: 'GET',
            url: 'http://mapi.zjzdy.net/api/ApiSchoolMsg/GetExpandUrl',
            data: { url: $scope.param.url },
            dataType: 'json',
            success: function (data, textStatus) {
                if (data.success) {
                    $scope.target.shortUrl = data.data;
                    console.log(data.data);
                    $scope.apply();
                    //请求成功
                } else {
                    console.log(data.Message);
                    //请求失败
                }
            },
            error: function (xmlHttpRequest, textStatus, errorThrown) {
                console.log(xmlHttpRequest.responseText)
                //$scope.alert(xmlHttpRequest.responseText);
            }
        });
    }



    //设置标题切换
    //$scope.activeTab = 0;
    //$scope.setActiveTab = function (index) {
    //    $scope.activeTab = index;
    //}
});